<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/vue.js"></script>
    <script src="js/axios.js"></script>
    <script src="js/elementUI.js"></script>
    <link rel="stylesheet" href="css/elementUI.css">
</head>
<body>
<div id="app">
    账号：<input type="text" v-model="user.username"> <br>
    密码：<input type="text" v-model="user.password"> <br>
    <input type="button" @click="login" value="登录">
</div>
<script>
    let vue = new Vue({
        el:"#app",
        data:{
            user:{
                username:"",
                password:""
            }
        },
        methods:{
            login(){
                axios.post("/user/login",this.user).then(res=>{
                    if(res.data){
                        localStorage.setItem("user",JSON.stringify(res.data));
                        if (res.data.roleName == "普通用户") {
                            location.href="messageList.html";
                        }
                        if (res.data.roleName == "管理员") {
                            location.href="message.html";
                        }
                    }else{
                        this.$message.error("账号或密码错误！");
                    }
                })
            }
        },
        created(){

        }
    })
</script>
</body>
</html>